//
//  HeadLineView.swift
//  AmountBody
//
//  Created by Qiu Jishuai on 2018/1/26.
//  Copyright © 2018年 RCMTM. All rights reserved.
//

import Foundation

@objcMembers
class HeadlineView: UIView {

    var title: String? {
        set {
            label.text = newValue
        }
        get {
            return label.text
        }
    }

    let label: UILabel = {
        let label = UILabel()
        label.textAlignment = .center
        label.numberOfLines = 1
        label.font = UIFont.systemFont(ofSize: 14)
        label.textColor = UIColor(hexString: "#363636");
        return label
    }()

    let leftImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.image = #imageLiteral(resourceName: "infolist_header_left")
        imageView.contentMode = .center
        return imageView
    }()

    let rightImageView: UIImageView = {
        let imageView = UIImageView()
        imageView.image = #imageLiteral(resourceName: "infolist_header_right")
        imageView.contentMode = .center
        return imageView
    }()

    override init(frame: CGRect) {
        super.init(frame: frame)

        setup()
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)

        setup()
    }

//    override var intrinsicContentSize: CGSize {
//        return CGSize(width: , height: 22)
//    }

    private func setup() {
        backgroundColor = .white
        addSubview(leftImageView)
        addSubview(rightImageView)
        addSubview(label)

        label.mas_makeConstraints { (make) in
            make?.height.greaterThanOrEqualTo()(22)
            make?.width.greaterThanOrEqualTo()(60)
            make?.center.top().bottom().equalTo()(self)
        }

        leftImageView.mas_makeConstraints { (make) in
            make?.centerY.equalTo()(label)
            make?.right.equalTo()(label.mas_left)?.offset()(-12)
            make?.left.equalTo()(self)
        }

        rightImageView.mas_makeConstraints { (make) in
            make?.right.equalTo()(self)
            make?.centerY.equalTo()(label)
            make?.left.equalTo()(label.mas_right)?.offset()(12)
        }
    }
}
